<?php
/**
 * @copyright: ©2024 永州 微聚商网络科技有限公司
 * @link: https://www.wEijuyunke.com
 */

namespace app\mobile\controller;
use app\admin\model\Platform;
use app\admin\model\template\ClaimConsume;
use app\BaseController;

/**
 * 定时任务操作
 *
 * @author Administrator
 *
 */
class Timer extends BaseController
{

    public function consumerExpire(){
        $consumerClaimLogModel = new \app\admin\model\ConsumerClaimLog();
        $consumerClaimLogList =  $consumerClaimLogModel->where('expire_time','>',time())->find();
        foreach ($consumerClaimLogList as $value ){
            if ($value['expire_time'] - time() < 86400){
                $userModel = new \app\admin\model\User();
                $userInfo = $userModel->where(['id' => $value['uid']]);
                if ($userInfo['openid']){
                    $platformModel = new Platform();
                    $platformInfo = $platformModel->where(['id' =>  $value['platform_id']])->find();
                    $templateModel   = new \app\admin\model\Template();
                    $templateInfo = $templateModel->where(['name'=>'consume_expire',
                        'platform_id'=> $value['platform_id']])->find();


                    $sendData = [
                        'template_id' => $templateInfo['template_id'],
                        'appid' => $platformInfo['xcx_appid'],
                        'appsecret' => $platformInfo['xcx_appsecret'],
                        'openid' => $userInfo['openid'],
                        'name' => '满'.$value['satisfy_amount'].'减'.$value['deductible_amount'],
                        'expire_time' =>date('Y-m-d H:i:s'),
                        'day' =>'不足1天',
                    ];
                    $ClaimConsumeTemplate = new ClaimConsume();
                    $ClaimConsumeTemplate->send($sendData);

                }
            }
        }

    }



}